<%@ page language="java" errorPage="/error.jsp" pageEncoding="UTF-8" contentType="text/html;charset=utf-8" %>
<%@ include file="/common/taglibs.jsp"%>

<head>
    <title>更改用户权限</title>
</head>
<body>
<s:if test="%{user!=null}">
<h1>编辑用户  <s:property value="user.username"/>(<s:property value="user.name"/>) </h1>
</s:if>
<s:else>
<script>
	function checkUsername(){
		var username = $('signup_user_username').value;
		var pattern = /^[a-zA-Z\d]+([\w\.\-]*[a-zA-Z\d]+)?$/;
		var pattern1 = /\s+/;
		var errorTip;
		var form = $('signup');
		
		if(username.length < 4 || username.length > 18){
			validation.clearErrorMessages(form);
			validation.clearErrorLabels(form);
			if(username.length < 4){
				errorTip = '用户名太短,';
			}else if(username.length > 18){
				errorTip = '用户名太长,';
			}
			errorTip += '用户名长度为4~18位';
			validation.addError($('signup_user_username'), errorTip);
			return;
		}
		if(!pattern.test(username)){
			validation.clearErrorMessages(form);
			validation.clearErrorLabels(form);
			if(pattern1.test(username)){
				errorTip = '用户名中不能包含空格';
			}else {
				errorTip = '用户名只能以字母、数字开头和结尾';
			}
			validation.addError($('signup_user_username'), errorTip);
			return;
		}
		var url = '<s:url value="/register/isUserExist.do"/>';
		jQuery.getJSON(url,{'user.username':username},
				function(dataFromServer){
					validation.clearErrorMessages(form);
					validation.clearErrorLabels(form);
					if(dataFromServer[4].isUsernameExist){
						validation.addError($('signup_user_username'), '该用户名已经存在，请使用其他用户名来注册.');
					}
				});
	}
	 
</script>
<h1>添加新用户</h1>
</s:else>



<s:form id="signup" action="save" validate="true">
<s:hidden name="userid" />

	<s:hidden key="user.id"/>
	<s:hidden name="key"></s:hidden>
				
	<s:if test="%{user!=null}">
		<s:hidden key="user.username"/>
	</s:if>
	<s:else>
		<s:textfield key="user.username" cssClass="text medium" required="true" onchange="checkUsername()"/>
		<div style="width:230px;background:#F3F3F3 none repeat scroll 0 0;color:#666666;">
			<div>·由字母a～z(不区分大小写)、数字0～9、点、减号或下划线组成</div>
			<div>·只能以数字或字母开头和结尾，且长度为4～18位</div>
		</div>
	</s:else>
	<s:textfield key="user.name" required="true" cssClass="text medium" inputcolspan="3"/>				
	<s:if test="%{user==null}">
		<s:password key="user.password" showPassword="true" required="true" 
			                    cssClass="text medium" inputcolspan="3"/>
    </s:if>
	<s:else>
    	<input type="hidden" name="user.password" value="123456"/>
    </s:else>
   	<s:textfield key="user.email" required="true" maxlength="255" cssClass="text medium" inputcolspan="3"/>
	<s:textfield key="user.mobile" required="false" maxlength="255"cssClass="text medium" inputcolspan="3"/>
	<s:textfield key="user.phoneNumber" required="false" maxlength="255" cssClass="text medium" inputcolspan="3"/>
	
	<s:checkbox  label="是否启用" name="user.enabled" />      
          
	<s:checkboxlist  
           label="用户组"
           list="rolegroupList"
           listKey="id"
           listValue="name"
           name="roleGroupIds"
           inputcolspan="3"
          />
           
          
 	<s:submit value="提交" />	
</s:form> 

 
</body>